/********************************************************************************
 * Copyright(c) 2020-2025 BST All rights reserved.
 * - Filename
 * - Author
 * - Version V1.0.0
 * - Date    2023/07/04
 * - Brief
 * - FunctionList:
 ******************************************************************************
 * History:
 *
 *
 *
 ******************************************************************************
 */

#include "Lidar.hpp"
#include "apollolidar/ApolloLidarAdapter.h"
#include "innolidar/InnoLidarAdapter.h"
#include "lslidar/LsLidarAdapter.h"
#include "rslidar/RsLidarAdapter.h"

using namespace lidar;
using namespace lslidar;
using namespace innolidar;

Lidar::Builder &Lidar::Builder::interface(const std::string &interface) {
  _interface = interface;
  return *this;
}

Lidar::Builder &Lidar::Builder::id(int id) {
  _id = id;
  return *this;
}

Lidar::Builder &Lidar::Builder::ip(const std::string &ip) {
  _ip = ip;
  return *this;
}

Lidar::Builder &Lidar::Builder::data_port(int p) {
  _data_port = p;
  return *this;
}

Lidar::Builder &Lidar::Builder::dev_port(int p) {
  _dev_port = p;
  return *this;
}

Lidar::Builder &Lidar::Builder::type(const std::string &t) {
  _type = t;
  return *this;
}

Lidar::Builder &Lidar::Builder::model(const std::string &m) {
  _model = m;
  return *this;
}

std::unique_ptr<Lidar> Lidar::Builder::build() {
  std::cout << _type << std::endl;
  if (_type == "leisheng") {
    return std::make_unique<LsLidarAdapter>(_id, _data_port, _dev_port);
  } else if (_type == "inno") {
    std::cout << " create inno lidar  " << std::endl;
    return std::make_unique<InnoLidarAdapter>(_id, _ip, _data_port, _dev_port);
  } else if (_type == "apollo") {
    std::cout << " create apollo lidar  " << std::endl;
    return std::make_unique<ApolloLidarAdapter>(_interface, _ip, _id);
  } else if (_type == "robosense") {
    std::cout << " create robosense lidar  " << std::endl;
    return std::make_unique<RsLidarAdapter>(_id, _ip, _data_port, _dev_port,
                                            _model);
  }
  return nullptr;
}
